<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateOrdersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('orders', function (Blueprint $table) {
            $table->id();
            $table->integer('user_id')->unsigned()->comment('用户id');
            $table->integer('store_id')->unsigned()->default(0)->comment('店铺id');
            $table->string('order_code')->default('')->comment('订单编号');
            $table->integer('pay_user_id')->unsigned()->comment('支付人:自己支付时记录自己用户ID，代付时记录代付人的用户ID');
            $table->tinyInteger('order_status')->default(0)->comment('订单状态: 超时取消0/已取消1/待付款2/待发货3/待收货4/已收货5/退款中6/已退款7');
            $table->tinyInteger('type')->default(0)->comment('会员订单1');
            $table->string('accepter_name')->default('')->comment('收货人名字');
            $table->string('accepter_phone')->default('')->comment('收货人手机');
            $table->string('province_name')->default('')->comment('收货地址省');
            $table->string('city_name')->default('')->comment('收货地址市');
            $table->string('district_name')->default('')->comment('区县名字');
            $table->string('detail_address')->default('')->comment('详细地址');
            $table->integer('national_code')->unsigned()->default(0)->comment('收货地址的国家码');
            $table->string('express_type', 100)->default('')->comment('快递用户选择的快递方式');
            $table->string('express_weight')->default('')->comment('快递重量 单位：克');
            $table->integer('express_price')->unsigned()->default(0)->comment('快递费,单位：分');
            $table->string('express_number')->default('')->comment('快递单号');
            $table->integer('base_price')->unsigned()->default(0)->comment('订单零售价');
            $table->integer('pay_price')->unsigned()->default(0)->comment('订单实付价');
            $table->integer('jf_price')->unsigned()->default(0)->comment('订单积分抵扣数额');
            $table->integer('jf')->unsigned()->default(0)->comment('订单积分数额');
            $table->datetime('express_at')->nullable()->comment('过期时间');
            $table->datetime('cancel_at')->nullable()->comment('取消时间');
            $table->datetime('pay_at')->nullable()->comment('支付时间');
            $table->datetime('send_at')->nullable()->comment('发货时间');
            $table->datetime('accept_at')->nullable()->comment('签收时间');
            $table->timestamps();
        });

        DB::statement("ALTER TABLE `orders` comment '订单主表'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('orders');
    }
}
